<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .box {
            width: 600px;
            height: 350px;
            border: 10px solid pink;
            margin: 30px auto;
            display: flex;
            flex-direction: column;
        }
        
        .box>ul {
            height: 80px;
            display: flex;
        }
        
        .box>ul>li {
            flex: 1;
            background-color: aqua;
            color: aliceblue;
            font-size: 34px;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
        }
        
        .box>ol {
            flex: 1;
            position: relative;
        }
        
        .box>ol>li {
            width: 100%;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
            display: none;
            justify-content: center;
            align-items: center;
            background-color: blueviolet;
            color: aliceblue;
            font-size: 100px;
        }
        
        .box>ul>li.active {
            background-color: orange;
        }
        
        .box>ol>li.active {
            display: flex;
        }
    </style>
    <div class="box" id="box1">
        <ul>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ul>
        <ol>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ol>
    </div>
    <div class="box" id="box2">
        <ul>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ul>
        <ol>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ol>
    </div>
    <div class="box" id="box3">
        <ul>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ul>
        <ol>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ol>
    </div>
    <script>
        function Tabs(select, type = "click") {
            this.ele = document.querySelector(select)
            this.btns = this.ele.querySelectorAll('ul>li');
            this.boxs = this.ele.querySelectorAll('ol>li');
            this.type = type;
            this.init();

        }
        Tabs.prototype.init = function() {
                this.btns.forEach((item, index) => {
                    item.addEventListener(this.type, () => {
                        for (let i = 0; i < this.btns.length; i++) {
                            this.btns[i].className = ''
                            this.boxs[i].className = ''
                        }
                        this.btns[index].className = 'active'
                        this.boxs[index].className = 'active'
                    })
                })
            }
            // const t1 = 
        new Tabs('#box1');
        new Tabs('#box2', 'mouseover');
        new Tabs('#box3');
        // t1.init();
        // console.log(t1);
    </script>
</body>

</html>